﻿using System;
using FluentAssertions;
using FluentAssertions.Assertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using ServiceProxy;

namespace CalculatorThree.UnitTests
{
    [TestClass]
    public class CalculatorTests
    {
        [TestMethod]
        public void Add_WhenClientProxyIsMocked_ShouldClientProxyBeCalled()
        {
            //Arrange
            var clientProxy = new Mock<IClientProxy<ICalculatorChannel>>();
            clientProxy.Setup(p => p.Execute(It.IsAny<Func<ICalculatorChannel, float>>())).Returns(42);
            var calculator = new Calculator(clientProxy.Object);

            //Act
            float response = calculator.Add(30, 12);

            //Assert

            /*It is not possible / quite difficult to check with which arguments the func was called. 
             * This has to do that Moq cannot evaluate the expression. Therefore only the call is checked. 
             * If we want to know if the correct arguments where set, we just mock the internal proxy of 
             * the client proxy (unit integration test) */

            clientProxy.Verify(c => c.Execute(It.IsAny<Func<ICalculatorChannel, float>>()), Times.Once());
            response.Should().BeApproximately(42, 0);
        }
    }
}